<?php

use Liriope\Component\Json\Json;

class GalleryController extends LiriopeController {

    // show()
    // displays a list of the latest blog posts
    //
    public function show( $vars=NULL ) {
        $page = $this->getPage();

        $gallery = new Gallery('data/gallery.json');
        $gallery->sortProjects();
        $tags = $gallery->getTags();
        $projects = $gallery->getProjects();

        $page->set( 'projects', $projects );
        $page->set( 'tags', $tags);
    }

    // project()
    //
    public function project( $vars=NULL ) {
        $page = $this->getPage();

        $id = a::get($vars, 0);

        $gallery = new Gallery('data/gallery.json');
        $project = $gallery->getProject($id);

        $page->set( 'project', $project );
    }

    public function image( $vars=NULL ) {
        $page = $this->getPage();

        $project = a::get($vars, 'id');
        $photo = a::get($vars, 'photo');

        $gallery = new Gallery('data/gallery.json');
        $project = $gallery->getProject($project);

        $photo = $project->getPhoto($photo);

        $page->set('photo', $photo);
    }

    public function tag($vars=NULL) {
        $page = $this->getPage();

        $tag = a::get($vars, 0);

        $gallery = new Gallery('data/gallery.json');
        $gallery->sortProjects();
        $projects = $gallery->getProjects();

        $collection = array();
        foreach($gallery->getProjects() as $key => $project) {
            if(a::contains($project->getTags(), $tag)) {
                $collection[$key] = $project;
            }
        }

        $page->set('collection', $tag);
        $page->set('gallery', $collection);
    }
}

